CmdUtils.makeSearchCommand({
 name: "search-oracle-docs",
 url: "http://search.oracle.com/search/search?group=Documentation&keyword={QUERY}",
 icon: "http://search.oracle.com/favicon.ico",
 description: "Search the Oracle documentation."
});

CmdUtils.makeSearchCommand({
  name: "search-scholar",
  url: "http://www.google.com/scholar?q={QUERY}",
  icon: "http://www.google.com/favicon.ico",
  description: "Searches Google Scholar for your words."
});


CmdUtils.makeSearchCommand({
  name: "search-torrentz",
  url: "http://www.torrentz.com/search?q={QUERY}",
  icon: "http://www.torrentz.com/favicon.ico",
  description: "Searches Torrentz.com for your ${query}."
});

CmdUtils.makeSearchCommand({
  name: "search-patent",
  url: "http://www.google.com/patents?q={QUERY}",
  icon: "http://www.google.com/favicon.ico",
  description: "Searches Google patents for ${query}",
  preview: function(pblock, directObject) {
	  var searchTerm = directObject.text;
	  var pTemplate = "Searches Google Patent for ${query}";
	  var pData = {query: searchTerm};
	  pblock.innerHTML = CmdUtils.renderTemplate(pTemplate, pData);

	  var url = "http://ajax.googleapis.com/ajax/services/search/patent";
	  var params = { v: "1.0", q: searchTerm };

	  jQuery.get( url, params, function(data) {
		  var numToDisplay = 3;
		  var results = data.responseData.results.splice( 0, numToDisplay );

		  pblock.innerHTML = CmdUtils.renderTemplate( {file:"google-search.html"},
			  {results:results}
			  );
		  }, "json");
  }
});

CmdUtils.CreateCommand({
  name: "yell",
  icon: "http://www.yell.com/favicon.ico",
  homepage: "http://mytechieself.blogspot.com/",
  author: {name: "Mskadu", email: "mskadu@gmail.com"},
  license: "MPL",  
  description: "Searches Yell.com for businesses in the UK",
  help: "Usage E.g.: yell Indian restaurants called Taj Mahal in NW1",
  takes: {"keywords": noun_arb_text},
  modifiers: {"named": noun_arb_text, 
              "in": noun_arb_text},
  preview: function (pblock, keywords, modifiers) {
     var txtKeywords = keywords.text;
	  var txtCompanyName = modifiers.named.text;
     var txtLocation = modifiers.in.text;

     if (keywords.text == "") txtKeywords = "e.g. national couriers, florists";
	  if (modifiers.named.text == undefined ||
		   modifiers.named.text == '') txtCompanyName = 'e.g. Yell';
     if (modifiers.in.text == undefined ||
         modifiers.in.text == '') txtLocation = "Eg. UK, town, postcode (Default: UNITED KINGDOM)";

      pblock.innerHTML = 'Searches Yell.com (UK-only) <ul>' +
                         '<li>For: <b>' + txtKeywords  + '</b></li>' + 
								 '<li>Named: <i>' + txtCompanyName + '</i></li>' + 
                         '<li>Located in: <i>' + txtLocation + '</i></li>' +
                         '</ul>';     
  },
  execute: function( keywords, modifiers ) {
     var strKeywords = keywords.text;

     /* replace unprovided param with null */
	  var strCompanyName = (modifiers.named.text==undefined?'':modifiers.named.text);
     var strLocation = (modifiers.in.text==undefined?'':modifiers.in.text); 

     if( strKeywords.length < 1) {
		  //Keywords are mandatory
       displayMessage('yell: No search terms provided. What you you want me to look for?');
	  }
     else {
     	 var strSearchUrl = 'http://www.yell.com/ucs/UcsSearchAction.do?keywords=' + escape(strKeywords) +
                            '&companyName=' + escape( strCompanyName ) +
                            '&location=' + escape(strLocation);
	 //displayMessage( strSearchUrl );
	 Utils.openUrlInBrowser( strSearchUrl );
      }

  }
});

